//
//  newsTableCell.m
//  IntroductionApp
//
//  Created by John Doe on 11/11/16.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "newsTableCell.h"

@implementation newsTableCell

@synthesize titleLabel = _titleLabel;
@synthesize mainLabel = _mainLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        // Title (改行禁止)
        CGRect titleRect = CGRectMake(5, 0 , 310, 20);
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:titleRect];
		titleLabel.numberOfLines = 0;
		titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        titleLabel.font = [UIFont boldSystemFontOfSize:14 ];
		titleLabel.textColor = [UIColor whiteColor];
		titleLabel.backgroundColor = [UIColor clearColor];
		titleLabel.text = @"";
		self.titleLabel = titleLabel;
		[self.contentView addSubview:self.titleLabel];
        
        // main (改行あり)
        CGRect mainRect = CGRectMake(5, 20, 310, 20);
        UILabel *mainLabel = [[UILabel alloc] initWithFrame:mainRect];
		mainLabel.numberOfLines = 0;
		mainLabel.lineBreakMode = UILineBreakModeCharacterWrap;
		mainLabel.font = [UIFont systemFontOfSize:13];
		mainLabel.textColor = [UIColor lightGrayColor];
		mainLabel.backgroundColor = [UIColor clearColor];
		mainLabel.text = @"";
		self.mainLabel = mainLabel;
		[self.contentView addSubview:self.mainLabel];
        
        [titleLabel release];
		[mainLabel release];
    }
    return self;
}

-(void)dealloc{
    _titleLabel = nil;
    _mainLabel = nil;
    [ super dealloc ];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setLabelText:(NSString*)title :(NSString*)main{
    
    // cellは選択させない
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    // titleの設定
    CGRect Trect = self.titleLabel.frame;
	CGSize Tsize = [title 
                   sizeWithFont:[UIFont systemFontOfSize:13]  
                   constrainedToSize:CGSizeMake(310, 9999) 
                   lineBreakMode:UILineBreakModeWordWrap];
    
    Trect.origin.y    =  0;
    Trect.size.height = Tsize.height;
    
    self.titleLabel.frame = Trect;
    [self.titleLabel setLineBreakMode:UILineBreakModeWordWrap];
    [self.titleLabel setNumberOfLines:0];    
    self.titleLabel.text = main;

    self.titleLabel.text = title;
    
    // mainLabelの高さを設定
    CGRect rect = self.mainLabel.frame;
	CGSize size = [main 
                   sizeWithFont:[UIFont systemFontOfSize:13]  
                   constrainedToSize:CGSizeMake(310, 9999) 
                   lineBreakMode:UILineBreakModeWordWrap];
    
    rect.origin.y    =  Tsize.height + 5;
    rect.size.height = size.height;
    
    self.mainLabel.frame = rect;
    [self.mainLabel setLineBreakMode:UILineBreakModeWordWrap];
    [self.mainLabel setNumberOfLines:0];
    
    self.mainLabel.text = main;
    
}

-(float)getNewsCellHeight{
    return  self.titleLabel.frame.size.height + self.mainLabel.frame.size.height - 5;
}

@end
